/**
* Class to hold the published and subscribed message declarations for a plugin component
*/
jsx3.lang.Class.defineClass("ux.core.util.component.Messaging",
        jsx3.lang.Object,
        null,
        function(config) {

            /**
             * {jsx3.util.List} List of {ux.core.util.component.Message} objects representing messages published by
             * this component
             * @private
             */
            config.prototype.publishedMessages = null;

            /**
             * {jsx3.util.List} List of {ux.core.util.component.Message} objects representing messages subscribed to by
             * this component
             * @private
             */
            config.prototype.listenedMessages = null;

            /**
             * Constructor for this class.
             *
             * @param entity {jsx3.xml.Entity} an xml node containing the information for a published and subscribed messages
             * @throws {ux.core.exception.InvalidComponentSchemaException} if the xml is invalid
             */
            config.prototype.init = function(entity) {
                this.jsxsuper();
                this.publishedMessages = new jsx3.util.List(0);
                this.listenedMessages = new jsx3.util.List(0);
                var children = entity.getChildNodes().iterator();
                while(children.hasNext()) {
                    var child = children.next();
                    var childName = child.getNodeName();
                    if(childName == "published_messages") {
                        var childMsgs = child.getChildNodes().iterator();
                        while(childMsgs.hasNext()) {
                            var childMsg = childMsgs.next();
                            var childMsgName = childMsg.getNodeName();
                            if(childMsgName == "message") {
                                this.publishedMessages.add(new ux.core.util.component.Message(childMsg),this.publishedMessages.size());
                            }
                        }
                    }
                    else if(childName == "listened_messages") {
                        var childMsgs = child.getChildNodes().iterator();
                        while(childMsgs.hasNext()) {
                            var childMsg = childMsgs.next();
                            var childMsgName = childMsg.getNodeName();
                            if(childMsgName == "message") {
                                this.listenedMessages.add(new ux.core.util.component.Message(childMsg),this.listenedMessages.size());
                            }
                        }
                    }
                }
            }

            /**
            * Returns an iterator of all of the published Messages.
            *
            * @return {jsx3.util.Iterator} an iterator for all of the published {ux.core.util.component.Message} objects.
            */
            config.prototype.getPublishedMessages =function() {
                return this.publishedMessages.clone().iterator();
            }

            /**
            * Returns an iterator of all of the listened Messages.
            *
            * @return {jsx3.util.Iterator} an iterator for all of the listened {ux.core.util.component.Message} objects.
            */
            config.prototype.getListenedMessages =function() {
                return this.listenedMessages.clone().iterator();
            }

            /**
            * Returns a string representing this object in the xml format specified by the component.xsd schema
            *
            * @param prepend {String} a string to be prepended to each line of the returned XML (useful for indenting)
            *
            * @returns {String} this ComponentConfig as XML, as specified by the component.xsd schema
            */
            config.prototype.toString = function(prepend) {
                if(!prepend) {
                    prepend + "";
                }
                var ret = prepend + "<messaging>\n";
                if(this.publishedMessages.size() > 0) {
                    ret += prepend + "   <published_messages>\n";
                    var iter = this.publishedMessages.iterator();
                    while(iter.hasNext()) {
                        ret += iter.next().toString(prepend + "      ");
                    }
                    ret += prepend + "   </published_messages>\n";
                }
                if(this.listenedMessages.size() > 0) {
                    ret += prepend + "   <listened_messages>\n";
                    var iter = this.listenedMessages.iterator();
                    while(iter.hasNext()) {
                        ret += iter.next().toString(prepend + "      ");
                    }
                    ret += prepend + "   </listened_messages>\n";
                }
                ret += prepend + "</messaging>\n";
                return ret;
            }
        }
);